#define uint unsigned int
#define uchar unsigned char

#define MOTOR_FAULT     RB0
#define GAS_GAUGE_ALCC  RB1

uint Logic_PowerStapler_CheckAdapter();
uint Logic_MotorDriver_CheckCuttingEnd();
uint Logic_MotorDriver_CheckOpenEnd();
uint Logic_MotorDriver_CheckCloseEnd();
uint Logic_MotorDriver_CheckReturnEnd();
uint Logic_MotorDriver_Return();
uint Logic_MotorDriver_ReturnPause();
uint Logic_MotorDriver_Phase_Safty();
uint Logic_MotorDriver_SaftyToOpenValue();
uint Logic_MotorDriver_CutReady();
uint Logic_MotorDriver_Cutting();
uint Logic_MotorDriver_CutPause();
uint Logic_MotorDriver_CutEnd();

extern void Device_MotorInitialize();
extern void Device_MotorSleep(uchar nSLEEP);
extern void Device_MotorReset(uchar nReset);
extern void Device_MotorDecayMode(uchar DecayMode);
extern uchar Device_MotorCheckFault();
extern void Device_MotorOutControl(uint);
extern void Device_MotorSetCurrent(int percentage);
extern unsigned int Device_LTC2943_ReadVoltage();
extern unsigned char  Device_LTC2943_ReadByte(unsigned int address);
extern unsigned char Device_LTC2943_AlertResponse();
extern void Device_Indicator_SetDirectorLED(uchar Dir, uchar Mode);
extern void Device_Indicator_SetLED(uchar SetLED);
extern uchar Device_Trigger_CheckFire();
extern uchar Device_Trigger_CheckDir();
extern uchar Device_LTC2943_CheckALCC();
extern uchar Device_Trigger_CheckSafe();
void Logic_ErrorProcess();
extern unsigned char Device_PowerCheckALCC(void);
#define Phase_INILIZATION     0
#define Phase_STANDBY         1
#define Phase_ELASTICCLOSURE  2
#define Phase_ELASTICOPEN     3
#define Phase_CUTTING         4
#define Phase_RETURN          5
#define Phase_ERROR           6
#define phase_SAFTY           7
#define phase_SAFTYTOOPEN     8
#define phase_CUTREADY        9
#define phase_CUTEND          10
#define phase_CUTPAUSE        11
#define phase_RETRUNPAUSE     12

#define NORMAL_WORK                                  0
#define STERILIZATION_COUNT_OVER                     1
#define POWER_MANAGE_BATTERY_NO_INSTALL              2
#define POWERSTAPLER_ADAPTER_NO_INSTALL              3
#define ELASTIC_CLOSURE_OVER_TIME                    4
#define ELASTIC_OPEN_OVER_TIME                       5
#define POWER_CURRENT_ALERT                          6
#define POWER_ACCUMULATED_CHARGE_OVER_UNDERFLOW      7
#define POWER_TEMPERATURE_ALERT                      8
#define POWER_CHARGE_ALERT_HIGH                      9
#define POWER_CHARGE_ALERT_LOW                       10
#define POWER_CHARGE_VOLTAGE_ALERT                   11
#define POWER_UNDERVOLTAGE_LOCKOUT_ALERT             12



#define STOP    0
#define FORWARD 1
#define BACK    2

#define ElasticClosureTurns   600
#define CutTurns              3000

#define SWITCH_ON   0
#define SWITCH_OFF  1

#define END         0
#define CONTINUE    1

extern struct TimerData
{
    uint Work_LED_Count;
};

extern struct SterilizationData
{
    uint count;
};
extern struct MotorControlData
{
    uint ElasticClosureCurrent;
    uint ElasticOpenCurrent;
    uint CuttingCurrent;
    uint ReturnCurrent;
    uint Director;
    uchar Feedback_Director;
    uint Turns_Number;
    uint Feedback_Turns_Number; 
    uchar nFault;
    uchar FeedbackStatus;
};
struct IndicatorData
{
    uchar ForwardLed_Flash;
    uchar BackLED_Flash;
    uchar LED_Status;
};
extern struct PowerStapler
{
    uint Phase_state;
    uint ErrorCode;
    struct SterilizationData Sterilization;
    struct MotorControlData MotorControl; 
    struct TimerData Timer;  
    struct IndicatorData Indicator;
};
extern struct PowerStapler PowerStaplerData;

extern int Charge_Status;
extern unsigned int warn_flag;
extern uint work_led_flag=0;